
#include "m_thread_cond.h"

m_cond::m_cond(){

	pthread_mutex_init(&mutex, NULL);
	pthread_cond_init(&cond, NULL);

}
void m_cond::lock(){
	pthread_mutex_lock(&mutex);
}
void m_cond::unlock(){
	pthread_mutex_unlock(&mutex);
}
void m_cond::wait(){
	pthread_cond_wait(&cond, &mutex);
}
void m_cond::signal(){
	pthread_cond_signal(&cond);
}
bool m_cond::timewaitms(long ms){
	struct timespec abstime;
	struct timeval now;
	long timeout_ms = ms;
	gettimeofday(&now, NULL);
	long nsec = now.tv_usec*1000+(timeout_ms%1000)*1000000;

	abstime.tv_sec = now.tv_sec + nsec/1000000000 + timeout_ms/1000;
	abstime.tv_nsec = nsec%1000000000;

	return pthread_cond_timedwait(&cond, &mutex, &abstime);
}
